package com.codeazur.as3swf.data.actions.swf4
{
   import com.codeazur.as3swf.SWFData;
   import com.codeazur.as3swf.data.actions.Action;
   import com.codeazur.as3swf.data.actions.ActionExecutionContext;
   import com.codeazur.as3swf.data.actions.IAction;
   import com.codeazur.as3swf.data.actions.IActionBranch;
   
   public class ActionIf extends Action implements IActionBranch
   {
      
      public static const CODE:uint = 157;
       
      
      protected var _branchOffset:int;
      
      protected var _branchIndex:int = -2;
      
      public function ActionIf(param1:uint, param2:uint, param3:uint)
      {
         super(param1,param2,param3);
      }
      
      public function get branchOffset() : int
      {
         return this._branchOffset;
      }
      
      public function set branchOffset(param1:int) : void
      {
         this._branchOffset = param1;
      }
      
      public function get branchIndex() : int
      {
         return this._branchIndex;
      }
      
      public function set branchIndex(param1:int) : void
      {
         this._branchIndex = param1;
      }
      
      override public function parse(param1:SWFData) : void
      {
         this._branchOffset = param1.readSI16();
      }
      
      override public function publish(param1:SWFData) : void
      {
         var _loc2_:SWFData = new SWFData();
         _loc2_.writeSI16(this._branchOffset);
         write(param1,_loc2_);
      }
      
      override public function clone() : IAction
      {
         var _loc1_:ActionIf = new ActionIf(code,length,pos);
         _loc1_.branchOffset = this._branchOffset;
         return _loc1_;
      }
      
      override public function toString(param1:uint = 0) : String
      {
         var _loc2_:* = " [";
         if(this._branchIndex >= 0)
         {
            _loc2_ = _loc2_ + this._branchIndex.toString();
         }
         else if(this._branchIndex == -1)
         {
            _loc2_ = _loc2_ + "EOB";
         }
         else
         {
            _loc2_ = _loc2_ + "???";
         }
         _loc2_ = _loc2_ + "]";
         return "[ActionIf] BranchOffset: " + this.branchOffset + _loc2_;
      }
      
      override public function toBytecode(param1:uint, param2:ActionExecutionContext) : String
      {
         var _loc3_:* = "";
         if(this._branchIndex >= 0)
         {
            _loc3_ = _loc3_ + param2.actions[this._branchIndex].lbl;
         }
         else if(this._branchIndex == -1)
         {
            _loc3_ = _loc3_ + ("L" + (param2.labelCount + 1));
         }
         else
         {
            _loc3_ = _loc3_ + "ILLEGAL BRANCH";
         }
         return toBytecodeLabel(param1) + "if " + _loc3_;
      }
   }
}
